package com.zz.cc.business.app;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import com.zz.cc.business.R;
import com.zz.cc.business.R.anim;
import com.zz.cc.business.R.id;
import com.zz.cc.business.R.layout;
import com.zz.common.app.BaseActivity;

public class LoginActivity extends BaseActivity implements OnClickListener, OnCheckedChangeListener {
	private static final int REQUEST_CODE_FOR_REGISTER = 9527;
	private static final int REQUEST_CODE_FOR_FORGET_PASSWORD = 9528;
	
	private EditText mUserNameInput;
	private EditText mPasswordInput;
	
	private Button mRegister;
	private Button mLoginer;
	
	private TextView mForgetPasswordInput;
	
	private RadioButton mExplanationer;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		initUI();
		fillView();
	}
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		
		if(requestCode == REQUEST_CODE_FOR_REGISTER) {
			//TODO register
		} else if(requestCode == REQUEST_CODE_FOR_FORGET_PASSWORD) {
			//nothing
		}
	}
	
	private void initUI() {
		mUserNameInput = (EditText) findViewById(R.id.login_input_user_name);
		mPasswordInput = (EditText) findViewById(R.id.login_input_password);
		mRegister = (Button) findViewById(R.id.login_register);
		mLoginer = (Button) findViewById(R.id.login_login);
		
		mForgetPasswordInput = (TextView) findViewById(R.id.login_forget_password);
		mExplanationer = (RadioButton) findViewById(R.id.login_explanation);
	}
	
	private void fillView() {
		mRegister.setOnClickListener(this);
		mLoginer.setOnClickListener(this);
		mForgetPasswordInput.setOnClickListener(this);
		mExplanationer.setOnCheckedChangeListener(this);
	}
	
	private void gotoMainActivity() {
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
		finish();
		overridePendingTransition(R.anim.activity_slide_right_in, R.anim.activity_slide_left_out);
	}
	
	private void gotoRegisterActivity() {
		Intent intent = new Intent(this, BaseInfoActivity.class);
		startActivityForResult(intent, REQUEST_CODE_FOR_REGISTER);
		overridePendingTransition(R.anim.activity_slide_right_in, R.anim.activity_slide_left_out);
	}

	private void gotoForgetPasswordActivity() {
		Intent intent = new Intent(this, ForgetPasswordActivity.class);
		startActivityForResult(intent, REQUEST_CODE_FOR_FORGET_PASSWORD);
		overridePendingTransition(R.anim.activity_slide_right_in, R.anim.activity_slide_left_out);
	}
	
	@Override	//View.OnClickListener
	public void onClick(View view) {
		switch(view.getId()) {
		case R.id.login_login:
			//TODO login
			gotoMainActivity();
			break;
			
		case R.id.login_register:
			gotoRegisterActivity();
			break;
			
		case R.id.login_forget_password:
			gotoForgetPasswordActivity();
			break;
			
		default:
			break;
		}
		
	}

	@Override	//OnCheckChangedListener
	public void onCheckedChanged(CompoundButton button, boolean check) {
		
	}

}
